package service;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONObject;
import utils.DBUtils;
import Dao.OrderOrRefuseDao;
import bean.LoginResult;

/**
 * Servlet implementation class OrderOrRefuseService
 */
public class OrderOrRefuseService extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public OrderOrRefuseService() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		HttpSession session=request.getSession();
		LoginResult loginResult=new LoginResult();
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		int toid=Integer.valueOf(request.getParameter("toid"));
		int type=Integer.valueOf(request.getParameter("type"));
		OrderOrRefuseDao dao=new OrderOrRefuseDao();
		PrintWriter writer = response.getWriter();
		boolean result=false;
		if(session.getAttribute("loginResult")!=null)
		{
			
			loginResult=(LoginResult) session.getAttribute("loginResult");
			int userid=loginResult.getUserid();
			result=dao.process(userid,toid,type);
		}
		JSONObject json=new JSONObject();
		json.put("status", result);
		writer.println(json.toString());
		writer.flush();
		writer.close();
	}

}
